package com.wad.manager.controller;

import com.github.pagehelper.PageInfo;
import com.wad.dto.product.CategoryBrandDto;
import com.wad.entity.product.CategoryBrand;
import com.wad.manager.service.CategoryBrandService;
import com.wad.vo.common.Result;
import com.wad.vo.common.ResultCodeEnum;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * @author wad
 * @date 2023/12/08 11:10
 * @project e-commerce
 **/

@RestController
@RequestMapping("/admin/product/categoryBrand")
public class CategoryBrandController {

    @Resource
    private CategoryBrandService categoryBrandService;

    //列表接口，搜索条件加分页条件
    @GetMapping("/list/{page}/{limit}")
    public Result list(@PathVariable("page") Integer page,
                       @PathVariable("limit") Integer limit,
                       CategoryBrandDto categoryBrandDto){
        PageInfo<CategoryBrand> pageInfo=categoryBrandService.findByPage(page,limit,categoryBrandDto);
        return Result.build(pageInfo, ResultCodeEnum.SUCCESS);
    }


    //新增接口
    @PostMapping("/save")
    public Result save(@RequestBody CategoryBrand categoryBrand){
        categoryBrandService.save(categoryBrand);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    //修改接口

    @PutMapping("/update")
    public Result update(@RequestBody CategoryBrand categoryBrand){
        categoryBrandService.update(categoryBrand);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }



    //删除
    @DeleteMapping("/deleteById/{id}")
    public Result deleteById(@PathVariable("id") Long id){
        categoryBrandService.deleteById(id);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }
}
